﻿// Models/Operator.cs
using Prism.Mvvm;
using System.ComponentModel;

namespace FullApp1.Modules.ModuleName.Models
{
    public class LegalPerson : BindableBase
    {
        private string _name;
        private string _ethnicity;
        private string _idNumber;
        private string _address;
        private DateTime _validDateStart; 
        private DateTime _validDateEnd;
        private DateTime _validityYears;
        private string _phone;
        private string _wechat;
        private string _education;

        public string Name
        {
            get => _name;
            set => SetProperty(ref _name, value);
        }

        public string Ethnicity
        {
            get => _ethnicity;
            set => SetProperty(ref _ethnicity, value);
        }

        public string IDNumber
        {
            get => _idNumber;
            set => SetProperty(ref _idNumber, value);
        }

        public string Address
        {
            get => _address;
            set => SetProperty(ref _address, value);
        }

        public DateTime ValidDateStart
        {
            get => _validDateStart;
            set
            {
                if (SetProperty(ref _validDateStart, value))
                {
                    OnPropertyChanged(new PropertyChangedEventArgs(nameof(ValidityYears))); // 触发关联属性更新
                }
            }
        }

        public DateTime ValidDateEnd
        {
            get => _validDateEnd;
            set
            {
                if(SetProperty(ref _validDateEnd, value))
                {
                    OnPropertyChanged(new PropertyChangedEventArgs(nameof(ValidityYears)));
                }
            }
        }

        public int ValidityYears
        {
            get
        {
            // 处理无效日期情况
            if (ValidDateStart == default || ValidDateEnd == default)
                return 0;

            // 直接计算年份差（不处理月份日期）
            return Math.Max(ValidDateEnd.Year - ValidDateStart.Year, 0);
        }
        }

        public string Phone
        {
            get => _phone;
            set => SetProperty(ref _phone, value);
        }

        public string Wechat
        {
            get => _wechat;
            set => SetProperty(ref _wechat, value);
        }

        public string Education
        {
            get => _education;
            set => SetProperty(ref _education, value);
        }
    }
}

